﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VietThuongLMS.Areas.Admin.Models;
using System.Text;

///Tin tuc Converter
///Author: NHDuc
///Created date: 02/12/2013
namespace VietThuongLMS.Utils
{
    public class Converter
    {
        private string[] arrChuyenDe = { "CD_GuitarThung", "CD_Violin", "CD_Flute", "CD_GuitarDien", 
                                         "CD_Viola", "CD_ThanhNhac", "CD_GuitarBass", "CD_Clarinet", 
                                         "CD_Keyboard", "CD_Piano", "CD_Saxophone", "CD_Trong", 
                                         "CD_NhacLy", "CD_ChuyenDeKhac" };
        private string[] arrChuyenDeVNI = { "Guitar thùng", "Violin", "Flute", "Guitar điện", 
                                         "Viola", "Thanh nhạc", "Guitar bass", "Clarinet", 
                                         "Keyboard", "Piano", "Saxophone", "Trống", 
                                         "Nhạc lý", "Khác" };
        private string[] arrThoiGian = { "Thứ 2", "Thứ 3", "Thứ 4", "Thứ 5", 
                                         "Thứ 6", "Thứ 7", "Chủ nhật" };

        //string date = "01/08/2008";
        public DateTime StringToDateTime(string date)
        {
            return Convert.ToDateTime(date);
        }

        public DateTime StringToDate(string date)
        {
            try
            {
                string[] arr = null;
                if (date.IndexOf("/") != -1)
                    arr = date.Split('/');
                else if (date.IndexOf("-") != -1)
                    arr = date.Split('-');
                if (arr.Length == 3)
                    return new DateTime(int.Parse(arr[2]), int.Parse(arr[1]), int.Parse(arr[0]));
                return DateTime.Now;
            }
            catch
            {
                return DateTime.Now;
            }
        }

        public string ChuyenDeParser(string chuyenDe)
        {
            string[] arr = chuyenDe.Split(new string[] {"*@*"}, StringSplitOptions.None);
            if (arr.Length != arrChuyenDe.Length)
                return chuyenDe;
            StringBuilder temp = new StringBuilder();
            for (int i=0; i<arr.Length; i++)
            {
                if (arr[i].ToLower() == "true")
                    temp.Append(arrChuyenDeVNI[i] + ", ");
            }

            return (temp.ToString().IndexOf(", ") != -1) ? temp.ToString().Substring(0, temp.ToString().Length-2) : temp.ToString();
        }

        public string ThoiGianHocParser(string chuyenDe)
        {
            string[] arr = chuyenDe.Split(new string[] { "*@*" }, StringSplitOptions.None);
            if (arr.Length != arrThoiGian.Length)
                return chuyenDe;
            StringBuilder temp = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                temp.Append(arrThoiGian[i] + ": " + arr[i] + "<br />");
            }

            return (temp.ToString().IndexOf(", ") != -1) ? temp.ToString().Substring(0, temp.ToString().Length - 2) : temp.ToString();
        }
        //Added by K
        public string GetStringMonney(string tiens)
        {
            string kq = " VNĐ";
            int t = 0;
            for (int i = tiens.Length - 1; i >= 0; i--)
            {
                t++;
                if (t == 3)
                {
                    kq = tiens.Substring(i, 3) + kq;
                    kq = "." + kq;
                    t=0;
                }
                if ((i == 0) && (t!=3))
                {
                    kq = tiens.Substring(0,t) + kq;
                }               
            }
            if (kq.ElementAt(0).ToString() == ".")
                return kq.Substring(1, kq.Length-1);
            return kq;
        }
        //End Addition

    }

    
    
}